﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tilver.Coder.Core;

namespace Tilver.Coder.Win.Views
{
    public partial class DataBaseView : UserControl
    {
        private CoderDataBase _dataBase;
        public CoderDataBase DataBase
        {
            get { return _dataBase; }
            set
            {
                _dataBase = value;
                textBoxNamespace.Text = _dataBase.NameSpace;
                textBoxName.Text = _dataBase.Name;
                textBoxConnectionString.Text = _dataBase.ConnectionString;
                comboBoxDataProvider.SelectedItem = _dataBase.DataProviderType;
            }
        }

        public DataBaseView()
        {
            InitializeComponent();

            comboBoxDataProvider.DataSource = System.Enum.GetValues(typeof(DataProviderTypeEnum));
            comboBoxDataProvider.SelectedItem = DataProviderTypeEnum.MSSQL;
            comboBoxDataProvider.Enabled = false;
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            _dataBase.DataProviderType = (DataProviderTypeEnum)comboBoxDataProvider.SelectedItem;
            _dataBase.ConnectionString = textBoxConnectionString.Text;
            _dataBase.Name = textBoxName.Text;
            _dataBase.NameSpace = textBoxNamespace.Text;
            buttonSave.Enabled = false;
        }
    }
}
